package com.example.rbacmanage.controller;

import com.example.rbacmanage.common.Result;
import com.example.rbacmanage.common.enums.UploadTypeEnum;
import com.example.rbacmanage.service.UploadFileService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/system/common")
public class CommonController {
    @Autowired
    private UploadFileService uploadFileService;

    @PostMapping(value = "/upload")
    public Result updateFile(@RequestParam("file") MultipartFile file){
        return Result.success(uploadFileService.uploadFile(UploadTypeEnum.LOCALUPLOAD.getType(),file));
    }

    @GetMapping(value = "/download")
    public void downloadFile(@RequestParam("filePath") String filePath, HttpServletResponse response){
        uploadFileService.downloadFile(response,filePath);
    }

    @GetMapping(value = "/remove")
    public void removeFile(@RequestParam("filePath") String filePath){
        uploadFileService.removeFile(filePath);
    }
}
